added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBSL3Animation / CodeBehindCreation.xaml.vb
blob4b9beed8d53e19595bddbc16d1637348218a4b4c
1 '***************************** Module Header ******************************\
2 '* Module Name: CodeBehindCreation.xaml.vb
3 '* Project: VBSL3Animation
4 '* Copyright (c) Microsoft Corporation.
5 '*
6 '* This module shows how to initialize a Storyboard in code behind. The final effect
7 '* is the same as BasicPointAnimation.xaml, which uses XAML to add Storyboard.
8 '*
9 '* This source is subject to the Microsoft Public License.
10 '* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 '* All other rights reserved.
12 '*
13 '* History:
14 '* * 9/10/2009 03:00 PM Allen Chen Created
15 '\**************************************************************************
17 Partial Public Class CodeBehindCreation
18 Inherits UserControl
20 Private _myAnimation As PointAnimation = New PointAnimation()
21 Private _myAnimationStoryboard As Storyboard = New Storyboard()
23 ''' <summary>
24 ''' In the following constructor, the PointAnimation is added to Storyboard.
25 ''' They are initialized for animation.
26 ''' </summary>
27 Public Sub New()
28 InitializeComponent()
29 _myAnimation.Duration = New Duration(TimeSpan.FromSeconds(2))
30 _myAnimation.SetValue(Storyboard.TargetPropertyProperty, New PropertyPath("Center"))
31 Storyboard.SetTarget(_myAnimation, MyAnimatedEllipseGeometry)
32 _myAnimationStoryboard.Children.Add(_myAnimation)
33 End Sub
35 ''' <summary>
36 ''' Tbe following event handler change the To property of PointAnimation object,
37 ''' then begin the Storyboard to play the animation. Please note we can change
38 ''' To property even when the animation is playing.
39 ''' </summary>
40 ''' <param name="sender"></param>
41 ''' <param name="e"></param>
42 Private Sub MyStackPanel_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
44 Dim targetpoint = e.GetPosition(Me.MyStackPanel)
45 Me._myAnimation.To = targetpoint
46 Me._myAnimationStoryboard.Begin()
48 End Sub
50 End Class